package com.yw.atp.model;

import java.util.Date;
import java.util.Set;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.yw.atp.Constant;
import com.yw.atp.util.DateUtil;


@Entity
@Table(name=Constant.DB_PREFIX+"weather")
public class Weather implements IDEntity{
	private static final long serialVersionUID = 1L;

	@Id
    @GeneratedValue
    private Integer id;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date date;	
	private String tem;
	private String message;
	private String currentTypePeriod;
	private String typePeriod1;
	private String statusPeriod1;
	private String typePeriod2;
	private String statusPeriod2;
	private String typePeriod3;
	private String statusPeriod3;
	private String typePeriod4;
	private String statusPeriod4;
	private String typePeriod5;
	private String statusPeriod5;
	private String typePeriod6;
	private String statusPeriod6;
	private String typePeriod7;
	private String statusPeriod7;
	private String typePeriod8;
	private String statusPeriod8;
	private String typePeriod9;
	private String statusPeriod9;
	private String typePeriod10;
	private String statusPeriod10;
	private String typePeriod11;
	private String statusPeriod11;
	private String typePeriod12;
	private String statusPeriod12;
	private String typeHalf1;
	private String statusHalf1;
	private String typeHalf2;
	private String statusHalf2;
	private String typeHalf3;
	private String statusHalf3;
	private String typeHalf4;
	private String statusHalf4;
	private String updateTime;
	private int version = 0;
	private Date updateAt;
	public Date getUpdateAt() {
		return updateAt;
	}

	public void setUpdateAt(Date updateAt) {
		this.updateAt = updateAt;
	}

	public String getCurrentTypePeriod() {
		return currentTypePeriod;
	}

	public void setCurrentTypePeriod(String currentTypePeriod) {
		this.currentTypePeriod = currentTypePeriod;
	}
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getTypePeriod1() {
		return typePeriod1;
	}

	public void setTypePeriod1(String typePeriod1) {
		this.typePeriod1 = typePeriod1;
	}

	public String getStatusPeriod1() {
		return statusPeriod1;
	}

	public void setStatusPeriod1(String statusPeriod1) {
		this.statusPeriod1 = statusPeriod1;
	}

	public String getTypePeriod2() {
		return typePeriod2;
	}

	public void setTypePeriod2(String typePeriod2) {
		this.typePeriod2 = typePeriod2;
	}

	public String getStatusPeriod2() {
		return statusPeriod2;
	}

	public void setStatusPeriod2(String statusPeriod2) {
		this.statusPeriod2 = statusPeriod2;
	}

	public String getTypePeriod3() {
		return typePeriod3;
	}

	public void setTypePeriod3(String typePeriod3) {
		this.typePeriod3 = typePeriod3;
	}

	public String getStatusPeriod3() {
		return statusPeriod3;
	}

	public void setStatusPeriod3(String statusPeriod3) {
		this.statusPeriod3 = statusPeriod3;
	}

	public String getTypePeriod4() {
		return typePeriod4;
	}

	public void setTypePeriod4(String typePeriod4) {
		this.typePeriod4 = typePeriod4;
	}

	public String getStatusPeriod4() {
		return statusPeriod4;
	}

	public void setStatusPeriod4(String statusPeriod4) {
		this.statusPeriod4 = statusPeriod4;
	}

	public String getTypePeriod5() {
		return typePeriod5;
	}

	public void setTypePeriod5(String typePeriod5) {
		this.typePeriod5 = typePeriod5;
	}

	public String getStatusPeriod5() {
		return statusPeriod5;
	}

	public void setStatusPeriod5(String statusPeriod5) {
		this.statusPeriod5 = statusPeriod5;
	}

	public String getTypePeriod6() {
		return typePeriod6;
	}

	public void setTypePeriod6(String typePeriod6) {
		this.typePeriod6 = typePeriod6;
	}

	public String getStatusPeriod6() {
		return statusPeriod6;
	}

	public void setStatusPeriod6(String statusPeriod6) {
		this.statusPeriod6 = statusPeriod6;
	}

	public String getTypePeriod7() {
		return typePeriod7;
	}

	public void setTypePeriod7(String typePeriod7) {
		this.typePeriod7 = typePeriod7;
	}

	public String getStatusPeriod7() {
		return statusPeriod7;
	}

	public void setStatusPeriod7(String statusPeriod7) {
		this.statusPeriod7 = statusPeriod7;
	}

	public String getTypePeriod8() {
		return typePeriod8;
	}

	public void setTypePeriod8(String typePeriod8) {
		this.typePeriod8 = typePeriod8;
	}

	public String getStatusPeriod8() {
		return statusPeriod8;
	}

	public void setStatusPeriod8(String statusPeriod8) {
		this.statusPeriod8 = statusPeriod8;
	}

	public String getTypePeriod9() {
		return typePeriod9;
	}

	public void setTypePeriod9(String typePeriod9) {
		this.typePeriod9 = typePeriod9;
	}

	public String getStatusPeriod9() {
		return statusPeriod9;
	}

	public void setStatusPeriod9(String statusPeriod9) {
		this.statusPeriod9 = statusPeriod9;
	}

	public String getTypePeriod10() {
		return typePeriod10;
	}

	public void setTypePeriod10(String typePeriod10) {
		this.typePeriod10 = typePeriod10;
	}

	public String getStatusPeriod10() {
		return statusPeriod10;
	}

	public void setStatusPeriod10(String statusPeriod10) {
		this.statusPeriod10 = statusPeriod10;
	}

	public String getTypePeriod11() {
		return typePeriod11;
	}

	public void setTypePeriod11(String typePeriod11) {
		this.typePeriod11 = typePeriod11;
	}

	public String getStatusPeriod11() {
		return statusPeriod11;
	}

	public void setStatusPeriod11(String statusPeriod11) {
		this.statusPeriod11 = statusPeriod11;
	}

	public String getTypePeriod12() {
		return typePeriod12;
	}

	public void setTypePeriod12(String typePeriod12) {
		this.typePeriod12 = typePeriod12;
	}

	public String getStatusPeriod12() {
		return statusPeriod12;
	}

	public void setStatusPeriod12(String statusPeriod12) {
		this.statusPeriod12 = statusPeriod12;
	}

	public String getTypeHalf1() {
		return typeHalf1;
	}

	public void setTypeHalf1(String typeHalf1) {
		this.typeHalf1 = typeHalf1;
	}

	public String getStatusHalf1() {
		return statusHalf1;
	}

	public void setStatusHalf1(String statusHalf1) {
		this.statusHalf1 = statusHalf1;
	}

	public String getTypeHalf2() {
		return typeHalf2;
	}

	public void setTypeHalf2(String typeHalf2) {
		this.typeHalf2 = typeHalf2;
	}

	public String getStatusHalf2() {
		return statusHalf2;
	}

	public void setStatusHalf2(String statusHalf2) {
		this.statusHalf2 = statusHalf2;
	}

	public String getTypeHalf3() {
		return typeHalf3;
	}

	public void setTypeHalf3(String typeHalf3) {
		this.typeHalf3 = typeHalf3;
	}

	public String getStatusHalf3() {
		return statusHalf3;
	}

	public void setStatusHalf3(String statusHalf3) {
		this.statusHalf3 = statusHalf3;
	}

	public String getTypeHalf4() {
		return typeHalf4;
	}

	public void setTypeHalf4(String typeHalf4) {
		this.typeHalf4 = typeHalf4;
	}

	public String getStatusHalf4() {
		return statusHalf4;
	}

	public void setStatusHalf4(String statusHalf4) {
		this.statusHalf4 = statusHalf4;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@OrderBy("createdAt desc")
	private Date createdAt;
    private String status = "0";;
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getTem() {
		return tem;
	}

	public void setTem(String tem) {
		this.tem = tem;
	}
    
	public static JSONArray capture(List<Weather> appms) throws JSONException{
		JSONArray jsonAppms = new JSONArray();
		for(Weather appm : appms){
			jsonAppms.put(appm.capture());
		}
		return jsonAppms;
	}
	
	public static JSONArray capture(Set<Weather> appms) throws JSONException{
		JSONArray jsonAppms = new JSONArray();
		for(Weather appm : appms){
			jsonAppms.put(appm.capture());
		}
		return jsonAppms;
	}
	
	public JSONObject capture() throws JSONException{
		JSONObject appm = new JSONObject();
		appm.put("id",id);
		appm.put("date",date!=null?DateUtil.getServiceFormat(date):"");	
		appm.put("tem",tem);
		appm.put("currentTypePeriod",currentTypePeriod);
		appm.put("message",message);
		appm.put("typePeriod1",typePeriod1);
		appm.put("statusPeriod1",statusPeriod1);
		appm.put("typePeriod2",typePeriod2);
		appm.put("statusPeriod2",statusPeriod2);
		appm.put("typePeriod3",typePeriod3);
		appm.put("statusPeriod3",statusPeriod3);
		appm.put("typePeriod4",typePeriod4);
		appm.put("statusPeriod4",statusPeriod4);
		appm.put("typePeriod5",typePeriod5);
		appm.put("statusPeriod5",statusPeriod5);
		appm.put("typePeriod6",typePeriod6);
		appm.put("statusPeriod6",statusPeriod6);
		appm.put("typePeriod7",typePeriod7);
		appm.put("statusPeriod7",statusPeriod7);
		appm.put("typePeriod8",typePeriod8);
		appm.put("statusPeriod8",statusPeriod8);
		appm.put("typePeriod9",typePeriod9);
		appm.put("statusPeriod9",statusPeriod9);
		appm.put("typePeriod10",typePeriod10);
		appm.put("statusPeriod10",statusPeriod10);
		appm.put("typePeriod11",typePeriod11);
		appm.put("statusPeriod11",statusPeriod11);
		appm.put("typePeriod12",typePeriod12);
		appm.put("statusPeriod12",statusPeriod12);
		appm.put("typeHalf1",typeHalf1);
		appm.put("statusHalf1",statusHalf1);
		appm.put("typeHalf2",typeHalf2);
		appm.put("statusHalf2",statusHalf2);
		appm.put("typeHalf3",typeHalf3);
		appm.put("statusHalf3",statusHalf3);
		appm.put("typeHalf4",typeHalf4);
		appm.put("statusHalf4",statusHalf4);
		appm.put("updateTime",updateTime);
		appm.put("createdAt",createdAt!=null?DateUtil.getServiceFormat(createdAt):"");
		appm.put("version",version);
		return appm;
	}
}
